package com.ruoyi.web.controller;

import java.util.Arrays;
import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.service.ISysUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.QuantifyProfit;
import com.ruoyi.web.service.IQuantifyProfitService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 量化收益信息Controller
 * 
 * @author ruoyi
 * @date 2023-05-19
 */
@Controller
@RequestMapping("/quantify/profit")
public class QuantifyProfitController extends BaseController
{
    private String prefix = "quantify/profit";

    @Autowired
    private IQuantifyProfitService quantifyProfitService;
    @Autowired
    private ISysUserService userService;
    @RequiresPermissions("quantify:profit:view")
    @GetMapping()
    public String profit()
    {
        return prefix + "/profit";
    }

    /**
     * 查询量化收益信息列表
     */
    @RequiresPermissions("quantify:profit:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(QuantifyProfit quantifyProfit)
    {
        startPage();
        List<QuantifyProfit> list = quantifyProfitService.selectQuantifyProfitList(quantifyProfit);
        return getDataTable(list);
    }

    /**
     * 导出量化收益信息列表
     */
    @RequiresPermissions("quantify:profit:export")
    @Log(title = "量化收益信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(QuantifyProfit quantifyProfit)
    {
        List<QuantifyProfit> list = quantifyProfitService.selectQuantifyProfitList(quantifyProfit);
        ExcelUtil<QuantifyProfit> util = new ExcelUtil<QuantifyProfit>(QuantifyProfit.class);
        return util.exportExcel(list, "量化收益信息数据");
    }

    /**
     * 新增量化收益信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存量化收益信息
     */
    @RequiresPermissions("quantify:profit:add")
    @Log(title = "量化收益信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(QuantifyProfit quantifyProfit)
    {
        return toAjax(quantifyProfitService.insertQuantifyProfit(quantifyProfit));
    }

    /**
     * 修改量化收益信息
     */
    @RequiresPermissions("quantify:profit:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        QuantifyProfit quantifyProfit = quantifyProfitService.selectQuantifyProfitById(id);
        SysUser user=userService.selectUserByLoginName(quantifyProfit.getLoginName());
        user = null==user?new SysUser():user;
        mmap.put("quantifyProfit", quantifyProfit);
        mmap.put("users", Arrays.asList(user));
        return prefix + "/edit";
    }

    /**
     * 修改保存量化收益信息
     */
    @RequiresPermissions("quantify:profit:edit")
    @Log(title = "量化收益信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(QuantifyProfit quantifyProfit)
    {
        return toAjax(quantifyProfitService.updateQuantifyProfit(quantifyProfit));
    }

    /**
     * 删除量化收益信息
     */
    @RequiresPermissions("quantify:profit:remove")
    @Log(title = "量化收益信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(quantifyProfitService.deleteQuantifyProfitByIds(ids));
    }

    @PostMapping("/user/list")
    @ResponseBody
    public TableDataInfo list(SysUser user)
    {
        startPage();
        List<SysUser> list = userService.selectUserList(user);
        return getDataTable(list);
    }
}
